/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						 table.cpp

	$Header: /resource_editor/table.cpp $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "table.h"

#include "streambuf_operators.h"

char const t_resource_traits<t_table>::prefix[] = "table";

char const t_resource_traits<t_table>::extension[] = "txt";

int  t_table::get_column_count() const
{
	int result = 0;

	const_iterator index;

	for (index = begin(); index != end(); index++)
	{
		if (index->size() > result)
			result = index->size();
	}
	return result;
}

bool t_table::read( std::streambuf& buffer )
{
	int count = get<int>( buffer );
	iterator index;

	resize( count );
	index = begin();
	while (count--)
	{
		if (!::read( buffer, *index ))
			return false;
		index++;
	}
	return true;
}

bool t_table::write( std::streambuf& buffer ) const
{
	const_iterator index = begin();

	put<int>( buffer, size() );
	while (index != end())
	{
		if (!::write( buffer, *index ))
			return false;
		index++;
	}
	return true;
}
